home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1368 / 1368.xpi / chrome / clrtabs.jar / content / clrtabs.js < prev    next >
Text File  |  2010-01-31  |  37KB  |  1,095 lines

  1. /*
  2. rgb(147, 174, 229)    hsl(220, 61%, 74%)        #FFDA75
  3. rgb(255, 218, 117)    hsl(44, 100%, 73%)        #FFDA75
  4. rgb(188, 204, 157)    hsl(80, 32%, 71%)        #BCCC9D
  5. rgb(239, 157, 159)    hsl(359, 72%, 78%)        #EF9D9F
  6. rgb(186, 167, 225)    hsl(260, 49%, 77%)        #BAA7E1
  7. rgb(155, 191, 180)    hsl(162, 22%, 68%)        #9BBFB4
  8. rgb(247, 180, 130)    hsl(26, 88%, 74%)        #F7B482
  9. rgb(216, 171, 192)    hsl(332, 37%, 76%)        #D8ABC0
  10. rgb(147, 229, 174)    hsl(140, 61%, 74%)        #93E5AE
  11. rgb(255, 117, 218)    hsl(316, 100%, 73%)        #FF75DA
  12. rgb(188, 157, 204)    hsl(280, 32%, 71%)        #BC9DCC
  13. rgb(239, 159, 157)    hsl(1, 72%, 78%)        #EF9F9D
  14. rgb(186, 225, 167)    hsl(100, 49%, 77%)        #BAE1A7
  15. rgb(155, 180, 191)    hsl(198, 22%, 68%)        #9BB4BF
  16. rgb(247, 130, 180)    hsl(334, 88%, 74%)        #F782B4
  17. rgb(216, 192, 171)    hsl(28, 37%, 76%)        #D8C0AB
  18. rgb(174, 147, 229)    hsl(260, 61%, 74%)        #AE93E5
  19. rgb(218, 255, 117)    hsl(76, 100%, 73%)        #DAFF75
  20. rgb(204, 188, 157)    hsl(40, 32%, 71%)        #CCBC9D
  21. rgb(157, 239, 159)    hsl(121, 72%, 78%)        #9DEF9F
  22. rgb(167, 186, 225)    hsl(220, 49%, 77%)        #A7BAE1
  23. rgb(191, 155, 180)    hsl(318, 22%, 68%)        #BF9BB4
  24. rgb(180, 247, 130)    hsl(94, 88%, 74%)        #B4F782
  25. rgb(171, 216, 192)    hsl(148, 37%, 76%)        #ABD8C0
  26. rgb(229, 174, 147)    hsl(20, 61%, 74%)        #E5AE93
  27. rgb(117, 218, 255)    hsl(196, 100%, 73%)        #75DAFF
  28. rgb(157, 204, 188)    hsl(160, 32%, 71%)        #9DCCBC
  29. rgb(159, 157, 239)    hsl(241, 72%, 78%)        #9F9DEF
  30. rgb(225, 167, 186)    hsl(340, 49%, 77%)        #E1A7BA
  31. rgb(180, 191, 155)    hsl(7%, 22%, 68%)        #B4BF9B
  32. rgb(130, 180, 247)    hsl(214, 88%, 74%)        #82B4F7
  33. rgb(192, 171, 216)    hsl(268, 37%, 76%)        #C0ABD8
  34. x,22-100,68-78
  35. x,61,73
  36. */
  37.  
  38.  
  39.  
  40.  
  41.  
  42. var ct = 
  43.     {
  44.     tabColors: ['rgb(147, 174, 229)','rgb(255, 218, 117)','rgb(188, 204, 157)','rgb(239, 157, 159)','rgb(186, 167, 225)','rgb(155, 191, 180)','rgb(247, 180, 130)','rgb(216, 171, 192)','rgb(147, 229, 174)','rgb(255, 117, 218)','rgb(188, 157, 204)','rgb(239, 159, 157)','rgb(186, 225, 167)','rgb(155, 180, 191)','rgb(247, 130, 180)','rgb(216, 192, 171)','rgb(174, 147, 229)','rgb(218, 255, 117)','rgb(204, 188, 157)','rgb(157, 239, 159)','rgb(167, 186, 225)','rgb(191, 155, 180)','rgb(180, 247, 130)','rgb(171, 216, 192)','rgb(229, 174, 147)','rgb(117, 218, 255)','rgb(157, 204, 188)','rgb(159, 157, 239)','rgb(225, 167, 186)','rgb(180, 191, 155)','rgb(130, 180, 247)','rgb(192, 171, 216)'],
  45.     newVersion:null,//version of the version being installed
  46.     ctVersion:null,//version of the currently installed version
  47.     fadedeg:null,//variable 'fadedeg' tracks fade degree starting 0 to 9 translates to mozopacity 0 to 1 **some explaination mising**.
  48.     scheme:null,//the coloring scheme viz. fixed pallette, random, domain based, manual only - 0,1,2,3 res.
  49.     clr:0,//tracks the tab color when using fixed pallette
  50.     isSeamonkey:'',
  51.     isFlock:'',
  52.     clrSession:window.navigator.userAgent.toLowerCase().indexOf('seamonkey')>=0?Components.classes["@mozilla.org/suite/sessionstore;1"].getService(Components.interfaces.nsISessionStore):Components.classes["@mozilla.org/browser/sessionstore;1"].getService(Components.interfaces.nsISessionStore),
  53.     adv:null,//advanced pref enabled?1:0;
  54.     satmax:null,//max saturation
  55.     satmin:null,//min saturation
  56.     lummax:null,//max luminance
  57.     lummin:null,//min luminance
  58.     sat:null,//saturation of domain based coloring
  59.     lum:null,//luminance of domain based coloring
  60.     txtreverse:null,//reversing of the tabs' text-color
  61.     enabledomain:null,//enable domain presets?1:0
  62.     dpref:null,//domain-color combo prefs
  63.     ctdebug:0,//enable message dump  to console?1:0
  64.     colorunmatcheddomain:null,//color unmatched domains?1:0 - currently unused
  65.     
  66.     clrtabsInit: function()
  67.         {
  68.         ct.cl(window.navigator.userAgent);
  69.         isFlock=(window.navigator.userAgent.toLowerCase().indexOf('flock')>=0)?true:false;
  70.         if(isFlock)
  71.             {
  72.             document.getElementById('main-window').className=document.getElementById('main-window').className+" flock";
  73.             }
  74.         
  75.         ct.isSeamonkey = (window.navigator.userAgent.toLowerCase().indexOf('seamonkey')>=0)?true:false,
  76.         ct.setCtPref();
  77.         
  78.         var ctEM = Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);    
  79.         var ctAddon = ctEM.getItemForID("{0545b830-f0aa-4d7e-8820-50a4629a56fe}");
  80.         ct.newVersion = ctAddon.version;
  81.         if(ct.ctVersion != ct.newVersion)
  82.             {
  83.             if(window.navigator.onLine)
  84.                 {            
  85.                 Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).setCharPref("extensions.clrtabs.firstrun", ct.newVersion);
  86.                 gBrowser.addEventListener('load', ct.ctFirstRun, false);
  87.                 }
  88.             else 
  89.                 {
  90.                 }
  91.             }
  92.         ct.chkRestore();
  93.         
  94.         gBrowser.addEventListener("SSTabRestoring",ct.restoreTabClr,false);
  95.         gBrowser.addEventListener("TabOpen", ct.calcTabClr, false);
  96.         gBrowser.addEventListener("TabMove", ct.getMovedTab, false);
  97.         gBrowser.addEventListener("TabClose", ct.tabrem, false);
  98.         gBrowser.addEventListener("TabSelect", ct.fadeAllTabs, false);
  99.         gBrowser.mStrip.addEventListener("mouseover", ct.effectMouseIn, false);
  100.         gBrowser.mStrip.addEventListener("mouseout", ct.effectMouseOut, false);    
  101.         ct.initTabcontext();
  102.         ct.showRecolor();
  103.         window.removeEventListener('load', ct.clrtabsInit, false);
  104.         return;
  105.         },
  106. executeSoon: function(aFunc)
  107.     {
  108.     var tm = Components.classes["@mozilla.org/thread-manager;1"].getService(Components.interfaces.nsIThreadManager);
  109.     tm.mainThread.dispatch(
  110.         {
  111.         run: function()
  112.             {
  113.             aFunc();
  114.             }
  115.         },
  116.     Components.interfaces.nsIThread.DISPATCH_NORMAL);
  117.     },
  118. ctFirstRun: function()
  119.     {
  120.     ct.cl("running first run routine");
  121.     gBrowser.removeEventListener('load', ct.ctFirstRun, false);
  122.     var clrUrl;    
  123.     clrUrl = 'http://colorfultabs.binaryturf.com/?v='+escape(ct.newVersion);
  124.     //gBrowser.selectedTab = gBrowser.addTab(clrUrl); 
  125.     ct.executeSoon(function(){gBrowser.selectedTab = gBrowser.addTab(clrUrl); });
  126.     //alert(clrUrl); 
  127.     Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).setCharPref("extensions.clrtabs.firstrun", ct.newVersion);
  128.     },
  129.  
  130.  chkRestore: function()
  131.     {
  132.     var tab,tabClr;
  133.     if(Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("browser.startup.page") !=3)
  134.         {
  135.         ct.cl("Opening Homepage(s)"); //we are opening the homepage(s). we are not restoring the session. 
  136.         var tabLen = gBrowser.mPanelContainer.childNodes.length;
  137.         for(var tn=0;tn<tabLen;tn++)
  138.             {            
  139.             tab = gBrowser.mTabContainer.childNodes[tn];                    
  140.             switch (ct.scheme)
  141.                 {
  142.                 case 0:                     
  143.                     if(ct.clrSession.getTabValue(tab,"ctreadonly") == 1)
  144.                         break;                
  145.                     tabClr = ct.tabColors[ct.clr%32];                    
  146.                     ct.setColor(tab,tabClr);
  147.                     ct.clr++;
  148.                     break;
  149.                 case 1:                     
  150.                     if(ct.clrSession.getTabValue(tab,"ctreadonly") == 1)
  151.                         break;                
  152.                      
  153.                     var oldtabClr=ct.clrSession.getTabValue(tab,"tabClr" );
  154.                     if(oldtabClr)
  155.                         {
  156.                         tabClr = oldtabClr;
  157.                         }
  158.                     else
  159.                         {
  160.                         clrSat = ct.clrRand(ct.satmin,ct.satmax);    //for keeping saturation to match the old static template we need the saturation between 30 and 95;ideally could be min 30; add advanced  prefs later
  161.                         clrLum = ct.clrRand(ct.lummin,ct.lummax);    //for keeping saturation to match the old static template we need the luminance between 68 and 78
  162.                         //tabClr ='hsl('+Math.abs(ct.clrHash(tab.getAttribute('linkedpanel').replace(/panel/,"")))%360+','+clrSat+'%,'+clrLum+'%)';
  163.                         var randkey = parseInt(Math.random()*100000000000000).toString();    //generate a really random int
  164.                         tabClr ='hsl('+Math.abs(ct.clrHash(randkey))%360+','+clrSat+'%,'+clrLum+'%)';    
  165.                         ct.cl("linkedpanel:\t"+tab.getAttribute('linkedpanel')+"\t"+tabClr+"\t"+randkey);
  166.                         }
  167.                     ct.setColor(tab,tabClr);
  168.                     break;
  169.                 case 2:
  170.                     tab.linkedBrowser.addProgressListener(clrUrlListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);                     
  171.                     break;
  172.                 case 3:break;    
  173.                 }
  174.             }
  175.         }
  176.     else
  177.         {
  178.         ct.cl("Restoring Session");
  179.         ct.calcTabClr();
  180.         }
  181.     },
  182.  resetTabClr :function()
  183.     {     
  184.     var clrObj = document.popupNode;
  185.     if(clrObj.className=='tabbrowser-tabs')
  186.         {
  187.         clrObj=gBrowser.selectedTab;
  188.         }     
  189.         ct.setColor(clrObj, "-moz-dialog");
  190.         ct.clrSession.setTabValue(clrObj, "ctreadonly", 0);         
  191.         //ct.setTaBottomClr();        
  192.     },
  193. initTabcontext: function()
  194.     {    
  195.     if(Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBoolPref("extensions.clrtabs.menu").toString()=='true')
  196.         {         
  197.         var clrMenu1 = document.createElement("menu");
  198.         clrMenu1.setAttribute("label","ColorfulTabs");
  199.         clrMenu1.setAttribute("id","ctTabCtx");
  200.         
  201.         var clrMenu2 = document.createElement("menupopup");
  202.         clrMenu2.setAttribute("id","ctCtxPopup");
  203.         clrMenu1.appendChild(clrMenu2);
  204.         
  205.         var clrMenu3 = document.createElement("menuitem");
  206.         clrMenu3.addEventListener("command",ct.setUserClr,false);
  207.         clrMenu3.setAttribute("label", "Tab Color");
  208.         clrMenu2.appendChild(clrMenu3);        
  209.         
  210.         var clrMenu3a = document.createElement("menuitem");
  211.         clrMenu3a.addEventListener("command",ct.resetTabClr,false);
  212.         clrMenu3a.setAttribute("label", "Reset Color");
  213.         clrMenu2.appendChild(clrMenu3a);
  214.         
  215.         var clrMenu4 = document.createElement("menuitem");
  216.         clrMenu4.addEventListener("command",ct.showOptions,false);
  217.         clrMenu4.setAttribute("label", "Options");
  218.         clrMenu2.appendChild(clrMenu4);
  219.         
  220.         var ctSep = document.createElement("menuseparator");
  221.         ctSep.setAttribute('id','ctsep')         
  222.         
  223.         window.getBrowser().mStrip.childNodes[1].appendChild(ctSep);
  224.         window.getBrowser().mStrip.childNodes[1].appendChild(clrMenu1);
  225.         }
  226.     else
  227.         {
  228.         if(document.getElementById('ctsep'))
  229.         try
  230.             {
  231.             var ctwm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  232.             var ctenumerator = ctwm.getEnumerator('navigator:browser');
  233.             var ctwin; 
  234.             var ctItem1,ctItem2,ctBrowser;             
  235.             while(ctenumerator.hasMoreElements())
  236.                 {                 
  237.                 ctwin = ctenumerator.getNext();                 
  238.                 ctItem1 = ctwin.document.getElementById('ctsep');
  239.                 ctItem2 = ctwin.document.getElementById('ctTabCtx');
  240.                 ctBrowser = ctwin.getBrowser();
  241.                 ctBrowser.mStrip.childNodes[1].removeChild(ctItem1);                 
  242.                  ctBrowser.mStrip.childNodes[1].removeChild(ctItem2);                 
  243.                 }             
  244.             }
  245.         catch(e){dump(e);return;}
  246.         }     
  247.     },
  248.         
  249. showRecolor: function()
  250.         {
  251.         var showCtCtx = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBoolPref("extensions.clrtabs.menu").toString();
  252.         if(!showCtCtx) return;
  253.         if(ct.scheme == 1) //If the menu option has been turned on
  254.             {
  255.             //add the element
  256.             var clrMenu2a = document.createElement("menuitem");
  257.             clrMenu2a.addEventListener("command",ct.regenClr,false);
  258.             clrMenu2a.setAttribute("label", "Re-Color");
  259.             clrMenu2a.setAttribute("id", "ctRecol");
  260.             //clrMenu2a.setAttribute("modifiers", "shift");
  261.             clrMenu2a.setAttribute("key", "ctRecolor");
  262.             clrMenu2a.setAttribute("acceltext", "Alt+Shift+R");
  263.             document.getElementById('ctCtxPopup').appendChild(clrMenu2a);
  264.             }
  265.         else
  266.             {
  267.             //remove the element.... 
  268.             if(document.getElementById('ctCtxPopup'))
  269.             try
  270.                 {
  271.                 var ctwm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
  272.                 var ctenumerator = ctwm.getEnumerator('navigator:browser');
  273.                 var ctwin; 
  274.                 var ctItem1,ctBrowser;             
  275.                 while(ctenumerator.hasMoreElements())
  276.                     {                 
  277.                     ctwin = ctenumerator.getNext();                 
  278.                     ctItem2 = ctwin.document.getElementById('ctCtxPopup');
  279.                     ctBrowser = ctwin.getBrowser();
  280.                     ctItem2.removeChild(document.getElementById('ctRecolor'));
  281.                     }             
  282.                 }
  283.             catch(e){ct.cl(e);return;}     
  284.             }
  285.         },
  286.  
  287. regenClr: function()
  288.     {
  289.     //ct.cl("regenClr");
  290.     var clrObj;
  291.     if(document.popupNode) 
  292.         {
  293.         ct.cl(document.popupNode.nodeName);
  294.         clrObj = document.popupNode;
  295.         if(clrObj.nodeName!=('tab') && clrObj.nodeName != "xul:tab")
  296.         clrObj = gBrowser.selectedTab;        
  297.         }
  298.     else
  299.         {
  300.         clrObj = gBrowser.selectedTab;
  301.         ct.cl('gb.st'); 
  302.         }    
  303.     /*if(clrObj.className=='tabbrowser-tabs')
  304.         {
  305.         clrObj=gBrowser.selectedTab;
  306.         }    
  307.         */
  308.     var clrSat = ct.clrRand(ct.satmin,ct.satmax);    //for keeping saturation to match the old static template we need the saturation between 30 and 95;ideally could be min 30; add advanced  prefs later
  309.     var clrLum = ct.clrRand(ct.lummin,ct.lummax);    //for keeping saturation to match the old static template we need the luminance between 68 and 78
  310.  
  311.     //7641001910403507
  312.     //12646680001161
  313.     var randkey = parseInt(Math.random()*100000000000000).toString();    //generate a really random int
  314.     var tabClr ='hsl('+Math.abs(ct.clrHash(randkey))%360+','+clrSat+'%,'+clrLum+'%)';    
  315.     ct.cl(tabClr);
  316.     ct.setColor(clrObj,tabClr);
  317.     ct.clrSession.setTabValue(clrObj, "ctreadonly", 1);
  318.     },
  319.  
  320. showOptions: function()
  321.     {    
  322.     var features = "chrome,centerscreen,resizable=no,dialog=yes,toolbar,close=no,dependent=yes";
  323.     window.openDialog('chrome://clrtabs/content/clrtabsopt.xul','_blank',features);    
  324.     } ,
  325.  
  326. setCtPref: function()
  327.     {     
  328.     clrPrefObserver.register();
  329.     var clrprefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  330.     try
  331.         {
  332.         ct.fadedeg = clrprefs.getIntPref("extensions.clrtabs.fadedeg");
  333.         ct.scheme = clrprefs.getIntPref("extensions.clrtabs.scheme");
  334.         ct.ctVersion = clrprefs.getCharPref("extensions.clrtabs.firstrun");
  335.         ct.txtreverse = clrprefs.getBoolPref("extensions.clrtabs.txtreverse");
  336.         ct.enabledomain=clrprefs.getBoolPref("extensions.clrtabs.enabledomain");
  337.         ct.colorunmatcheddomain=clrprefs.getBoolPref("extensions.clrtabs.colorunmatcheddomain");
  338.         ct.dpref=clrprefs.getCharPref("extensions.clrtabs.dpref");
  339.         ct.dpref=ct.dpref.split("`");    
  340.         ct.standout=clrprefs.getBoolPref("extensions.clrtabs.standout");
  341.         ct.adv = clrprefs.getBoolPref("extensions.clrtabs.advanced");
  342.         if(ct.adv==false)//satmax,satmin,lummax,lummin;
  343.             {            
  344.             ct.satmax=100;
  345.             //clrprefs.setIntPref("extensions.clrtabs.satmax",satmax);
  346.             ct.satmin=22;
  347.             //clrprefs.setIntPref("extensions.clrtabs.satmin",satmin);
  348.             ct.lummax=78;
  349.             //clrprefs.setIntPref("extensions.clrtabs.lummax",lummax);
  350.             ct.lummin=68;
  351.             //clrprefs.setIntPref("extensions.clrtabs.lummin",lummin);
  352.             ct.sat=61;
  353.             ct.lum=73;
  354.             }
  355.         else
  356.             {
  357.             ct.satmax=clrprefs.getIntPref("extensions.clrtabs.satmax");
  358.             ct.satmin=clrprefs.getIntPref("extensions.clrtabs.satmin");
  359.             ct.lummax=clrprefs.getIntPref("extensions.clrtabs.lummax");
  360.             ct.lummin=clrprefs.getIntPref("extensions.clrtabs.lummin");
  361.             ct.sat=clrprefs.getIntPref("extensions.clrtabs.sat");
  362.             ct.lum=clrprefs.getIntPref("extensions.clrtabs.lum");
  363.             }
  364.         if(clrprefs.getBoolPref("extensions.clrtabs.bgpic")==true)
  365.             {            
  366.             if(ct.isSeamonkey)
  367.                 {
  368.                 
  369.                 ct.setSeamonkeyContainerBg(true);
  370.                 }
  371.             else
  372.                 {
  373.                 gBrowser.mTabContainer.style.backgroundImage="url("+clrprefs.getCharPref("extensions.clrtabs.bgpicpath")+")";
  374.                 gBrowser.mTabContainer.style.backgroundRepeat="repeat";
  375.                 }    
  376.             }        
  377.         }
  378.     catch(e)
  379.         {
  380.         dump(e);
  381.         }
  382.     },
  383.  
  384. calcTabClr:function(event)
  385.     {
  386.     var tab;
  387.     var clrSat,clrLum,tabClr;
  388.     if(event)
  389.         {
  390.         tab = event.originalTarget;
  391.         
  392.         /*ct.cl("\n\n\n");
  393.         ct.cl("event.explicitOriginalTarget:\t"+event.explicitOriginalTarget.nodeName );
  394.         ct.cl("event.currentTarget:\t"+event.currentTarget.nodeName  );
  395.         ct.cl("event.originalTarget:\T"+event.originalTarget.nodeName  );
  396.         ct.cl("event.type:\t"+event.type   );
  397.         ct.cl("event.view:\t"+event.view    );
  398.         ct.cl("event.detail:\t"+event.detail   );
  399.         ct.cl("event.which:\t"+event.which    );
  400.         if(event.explicitOriginalTarget.nodeName.toLowerCase() == "menuitem")
  401.             {
  402.             ct.cl("caught Menuitem");
  403.             tEl = event.explicitOriginalTarget;
  404.             while(tEl.parentNode)
  405.                 {
  406.                 tEl = tEl.parentNode;
  407.                 ct.cl("parent:\t"+tEl.nodeName);
  408.                 }
  409.             }
  410.         */
  411.         }
  412.     else
  413.         {
  414.         tab = gBrowser.mTabContainer.childNodes[0];
  415.         }     
  416.     switch (ct.scheme)
  417.         {
  418.         case 0:             
  419.                 if(ct.clrSession.getTabValue(tab,"ctreadonly") == 1)
  420.                     {
  421.                     return;
  422.                     }
  423.                  
  424.                 tabClr = ct.tabColors[ct.clr%32];
  425.                 ct.setColor(tab,tabClr);
  426.                 ct.clr++;                 
  427.             break;
  428.         case 1:             
  429.                 if(ct.clrSession.getTabValue(tab,"ctreadonly") == 1)
  430.                     {            
  431.                     return;
  432.                     }                
  433.                 var oldtabClr=ct.clrSession.getTabValue(tab,"tabClr" );                    
  434.                 if(oldtabClr)
  435.                     {                    
  436.                     tabClr = oldtabClr;
  437.                     }
  438.                 else
  439.                     {
  440.                     clrSat = ct.clrRand(ct.satmin,ct.satmax);    //for keeping saturation to match the old static template we need the saturation between 30 and 95;ideally could be min 30; add advanced  prefs later
  441.                     clrLum = ct.clrRand(ct.lummin,ct.lummax);    //for keeping saturation to match the old static template we need the luminance between 68 and 78
  442.                     ct.cl("linkedpanel:\t"+tab.getAttribute('linkedpanel'));
  443.                     //tabClr ='hsl('+Math.abs(ct.clrHash(tab.getAttribute('linkedpanel').replace(/panel/,"")))%360+','+clrSat+'%,'+clrLum+'%)';
  444.                     var randkey = parseInt(Math.random()*100000000000000).toString();    //generate a really random int
  445.                     tabClr ='hsl('+Math.abs(ct.clrHash(randkey))%360+','+clrSat+'%,'+clrLum+'%)';    
  446.                     ct.cl("linkedpanel:\t"+tab.getAttribute('linkedpanel')+"\t"+tabClr+"\t"+randkey);
  447.                     }
  448.                 ct.setColor(tab,tabClr);                 
  449.             break;
  450.         case 2:            
  451.             tab.linkedBrowser.addProgressListener(clrUrlListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);                 
  452.             break;
  453.         case 3:break;
  454.         }
  455.     //ct.cl("TabBGColor:"+tabClr);
  456.     },
  457.  
  458. setForeColor:function(tab)
  459.     {
  460.     if(ct.txtreverse)
  461.         {         
  462.         rgb = document.defaultView.getComputedStyle(tab, null).getPropertyValue("background-color").toString();
  463.         rgb = rgb.replace(/ /g,''); //strip spaces
  464.         re = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;
  465.         rgb.toLowerCase();
  466.         re.exec(rgb);
  467.         r = RegExp.$1
  468.         g = RegExp.$2;
  469.         b =    RegExp.$3;         
  470.         tab.style.setProperty('color','rgb('+(255-parseInt(r))+','+(255-parseInt(g))+','+(255-parseInt(b))+')','important');
  471.         }
  472.     else
  473.         {
  474.         tab.style.setProperty('color','rgb(0,0,0)','important');
  475.         }
  476.     },
  477.  reverseTxtColor:function()
  478.     {
  479.     try
  480.         {
  481.         var tblength = gBrowser.mPanelContainer.childNodes.length;
  482.         for(var loop = 0; loop < tblength; loop++)
  483.             {
  484.             try
  485.                 {
  486.                 ct.setForeColor(gBrowser.mTabContainer.childNodes[loop]);                 
  487.                 }
  488.             catch(e)
  489.                 {
  490.                 Components.utils.reportError(e);
  491.                 }
  492.             }
  493.         }
  494.     catch(e)
  495.         {
  496.         dump("\nColorfulTabs Log: Error: " + e);
  497.         }
  498.     },
  499.  setColor:function(tab, tabClr)
  500.     {
  501.     tab.style.setProperty('background-color',tabClr,'important');
  502.     ct.setForeColor(tab);
  503.     ct.clrSession.setTabValue(tab, "tabClr", tabClr);
  504.     //ct.setMIcolor(tab,tabClr);
  505.     ct.fadeAllTabs();
  506.     },
  507. setMIcolor:function(tab, tabClr)
  508.     {
  509.     try
  510.         {
  511.         tab.mCorrespondingMenuitem.style.setProperty('background-color',tabClr,'important');
  512.         }
  513.     catch(e){ct.cl(e);}
  514.     },
  515.  getMovedTab:function(event)
  516.     {
  517.     //ct.cl("TabMove");
  518.     if(event.originalTarget.nodeName == "tab" || event.originalTarget.nodeName == "xul:tab")
  519.         {         
  520.         var myClr = ct.clrSession.getTabValue(event.originalTarget, "tabClr");         
  521.         ct.setColor(event.originalTarget,myClr)         
  522.         }
  523.     },
  524.  restoreTabClr:function(event)
  525.     {    
  526.     var tab = event.originalTarget;
  527.     var myClr = ct.clrSession.getTabValue(tab, "tabClr");
  528.     //ct.cl("restoring Tabcolorvalue"+(ss.getTabValue(tab, "tabClr")?1:0));
  529.     if(myClr) //if 
  530.         {
  531.         ct.setColor(tab,myClr)
  532.         }    
  533.     },
  534.  clrHash:function(clrString)
  535.     {     
  536.     var hash = ct.SHA256(clrString);
  537.     var iClr, clrConst = 5381;// var clrString = ;
  538.         for (iClr = 0; iClr < hash.length; iClr++)
  539.         {
  540.         clrConst = ((clrConst << 5) + clrConst) + hash.charCodeAt(iClr);
  541.         }
  542.     return clrConst;
  543.     },
  544.  clrRand:function(min,max)
  545.     {     
  546.     return (Math.round(Math.random()*(max-min)))+min;
  547.     },
  548.  tabrem:function(event)
  549.     {    
  550.         //ct.cl("TabClose");
  551.     var tab = event.originalTarget.nodeName;     
  552.     },
  553.  cl:function(msg)
  554.     {
  555.     if(ct.ctdebug) dump("\ncl:\t"+msg);
  556.     },
  557. fadeNode:function(node,opacity)
  558.     {
  559.     node.style.setProperty('opacity',opacity,'important');
  560.     },
  561. fadeAllTabs:function(event)
  562.     {
  563.         //ct.cl("TabSelect")
  564.     ct.setTaBottomClr();     
  565.     try
  566.         {
  567.         var tblength = gBrowser.mPanelContainer.childNodes.length;
  568.         for(var loop = 0; loop < tblength; loop++)
  569.             {
  570.             try
  571.                 {                 
  572.                 if(ct.fadedeg)
  573.                     {
  574.                     for(var count=0;count< gBrowser.mTabContainer.childNodes.length;count++)                        
  575.                         ct.fadeNode(gBrowser.mTabContainer.childNodes[count],(10-ct.fadedeg)/10);                        
  576.                     }
  577.                 else
  578.                     {                    
  579.                     for(var count=0;count<gBrowser.mTabContainer.childNodes.length;count++)
  580.                         {
  581.                         ct.fadeNode(gBrowser.mTabContainer.childNodes[count],'1');
  582.                         }
  583.                     }
  584.                 }
  585.             catch(e)
  586.                 {
  587.                 Components.utils.reportError(e);
  588.                 }
  589.             }
  590.         }
  591.     catch(e)
  592.         {
  593.         dump("\nColorfulTabs Log: Error: " + e);
  594.         }
  595.     if(ct.standout)
  596.         {        
  597.         try
  598.             {         
  599.             for(var count=0;count< gBrowser.mTabContainer.childNodes.length;count++)                        
  600.                 gBrowser.mTabContainer.childNodes[count].className = gBrowser.mTabContainer.childNodes[count].className.replace(" standout","");            
  601.             }
  602.         catch(e)
  603.             {
  604.             ct.cl("\nColorfulTabs Error in function ct.fadeAllTabs: "+e+". standout "+count2);
  605.             }
  606.         gBrowser.selectedTab.className=gBrowser.selectedTab.className+" standout";
  607.         }
  608.     /*else
  609.         {
  610.         for(var count=0;count< gBrowser.mTabContainer.childNodes.length;count++)                        
  611.                 {
  612.                 if(gBrowser.mTabContainer.childNodes[count].className.match(" standout"))
  613.                     {
  614.                     gBrowser.mTabContainer.childNodes[count].className.replace(" standout","")
  615.                     }
  616.                 }
  617.         }
  618. */
  619. if(ct.fadedeg)
  620.         {
  621.         try
  622.             {             
  623.             ct.fadeNode(gBrowser.selectedTab,"1");
  624.             }
  625.         catch(e)
  626.             {
  627.             dump("\nColorfulTabs Error in function ct.fadeAllTabs: "+e+". Iteration failed on value "+count2);
  628.             }
  629.         }
  630.     },
  631. setTaBottomClr:function()
  632.     {
  633.     var ss = new Array();
  634.     var ss = document.styleSheets;
  635.     for (var i=0; i < ss.length; i++)
  636.         {
  637.         switch (ss[i].href)
  638.             {
  639.             case 'chrome://clrtabs/skin/clrtabs.css':
  640.             case 'chrome://clrtabs/skin/clrtabs-seamonkey.css':
  641.                 var clrSS = ss[i];
  642.                 break;
  643.             }
  644.         }
  645.     try
  646.         {
  647.         clrSS.cssRules[2].style.setProperty ('background-color',document.defaultView.getComputedStyle(gBrowser.selectedTab, null).getPropertyValue("background-color").toString() ,'important' );
  648.         }
  649.     catch(e)
  650.         {
  651.         dump("\nctlog:\terror in function ct.setTaBottomClr "+e);
  652.         }
  653.     },
  654. setSeamonkeyContainerBg:function(yes)
  655.     {
  656.     var clrPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getCharPref("extensions.clrtabs.bgpicpath");
  657.     //var clrPrefs =    Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getCharPref("extensions.clrtabs.bgpicpath");
  658.     var ss = new Array();
  659.     var ss = document.styleSheets;
  660.     ct.cl("attempting function")
  661.     for (var i=0; i < ss.length; i++)
  662.         {
  663.         switch (ss[i].href)
  664.             {
  665.             case 'chrome://clrtabs/skin/clrtabs-seamonkey.css':
  666.                 var clrSS = ss[i];
  667.                 break;
  668.             }
  669.         }
  670.     try
  671.         {
  672.         if(yes)
  673.             {
  674.             //alert(clrSS.cssRules[3].selectorText)
  675.             clrSS.cssRules[3].style.setProperty('background-image',"url("+clrPrefs+")" ,'important' ); 
  676.             clrSS.cssRules[3].style.setProperty('background-repeat', "repeat","important");
  677.             }
  678.         else
  679.             {
  680.             clrSS.cssRules[3].style.setProperty('background-image',"url('chrome://clrtabs/skin/seamonkey-bg.png')" ,'important' );
  681.             clrSS.cssRules[3].style.setProperty('background-repeat',"repeat-x" ,'important' );
  682.             }
  683.         }
  684.     catch(e)
  685.         {
  686.         dump("\nctlog:\terror in function ct.setSeamonkeyContainerBg "+e);
  687.         }
  688.     },
  689.  
  690. effectMouseIn:function(event)
  691.     {
  692.     if (event.target.nodeName != "xul:tab" && event.target.nodeName != "tab") { return; }
  693.     if((event.target.getAttribute('selected')=='true') ||(event.target.nodeName=='xul:tabs'))
  694.         return;
  695.     try
  696.         {
  697.         ct.fadeNode(event.target,1);
  698.         }
  699.     catch(e)
  700.         {
  701.         dump("\nColorfulTabs Error in function ct.effectMouseIn: "+e+". Iteration failed on value "+count2);
  702.         }
  703.     },
  704. effectMouseOut:function(event)
  705.     {
  706.     if (event.target.nodeName != "xul:tab" && event.target.nodeName != "tab") { return; }
  707.     if((event.target.getAttribute('selected')=='true') ||(event.target.nodeName=='xul:tabs'))
  708.         return;
  709.     try
  710.         {
  711.         ct.fadeNode(event.target,(10-ct.fadedeg)/10);
  712.         }
  713.     catch(e)
  714.         {
  715.         }
  716.     },
  717. setUserClr:function()
  718.     {
  719.     var clrObj = document.popupNode;
  720.     if(clrObj.className=='tabbrowser-tabs')
  721.         {
  722.         clrObj=gBrowser.selectedTab;
  723.         }    
  724.     var params = {inn:{oldColor:document.defaultView.getComputedStyle(clrObj, null).getPropertyValue("background-color"), enabled:0}, out:null};
  725.     window.openDialog('chrome://clrtabs/content/clrpkr.xul','_blank','modal,chrome,centerscreen,resizable=no, dialog=yes,close=no', params).focus();
  726.     if (params.inn.enabled)
  727.         {        
  728.         var clrNewColor = params.inn.oldColor;
  729.         ct.setColor(clrObj, clrNewColor.toString());
  730.         ct.clrSession.setTabValue(clrObj, "ctreadonly", 1);        
  731.         //ct.setTaBottomClr();
  732.         }
  733.     else
  734.         {
  735.         
  736.         }
  737.     },
  738. SHA256:function(s)
  739.     {
  740.     var chrsz   = 8;  
  741.     var hexcase = 0;         
  742.     
  743.     function safe_add (x, y)
  744.         {  
  745.         var lsw = (x & 0xFFFF) + (y & 0xFFFF);  
  746.         var msw = (x >> 16) + (y >> 16) + (lsw >> 16);  
  747.         return (msw << 16) | (lsw & 0xFFFF);  
  748.         }   
  749.     function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }  
  750.     function R (X, n) { return ( X >>> n ); }  
  751.     function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }  
  752.     function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }  
  753.     function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }  
  754.     function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }  
  755.     function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }  
  756.     function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }  
  757.     function core_sha256 (m, l)
  758.         {  
  759.     var K = new Array(0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2);  
  760.     var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);  
  761.     var W = new Array(64);  
  762.     var a, b, c, d, e, f, g, h, i, j;  
  763.     var T1, T2;  
  764.     m[l >> 5] |= 0x80 << (24 - l % 32);  
  765.     m[((l + 64 >> 9) << 4) + 15] = l;  
  766.     for ( var i = 0; i<m.length; i+=16 ) 
  767.         {  
  768.     a = HASH[0];  
  769.     b = HASH[1];  
  770.     c = HASH[2];  
  771.     d = HASH[3];  
  772.     e = HASH[4];  
  773.     f = HASH[5];  
  774.     g = HASH[6];  
  775.     h = HASH[7];
  776.     for ( var j = 0; j<64; j++)
  777.         {
  778.         if (j < 16) W[j] = m[j + i];  
  779.         else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);  
  780.         T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);  
  781.         T2 = safe_add(Sigma0256(a), Maj(a, b, c));  
  782.         h = g;  
  783.         g = f;  
  784.         f = e;  
  785.         e = safe_add(d, T1);  
  786.         d = c;  
  787.         c = b;  
  788.         b = a;  
  789.         a = safe_add(T1, T2);  
  790.         }  
  791.     HASH[0] = safe_add(a, HASH[0]);  
  792.     HASH[1] = safe_add(b, HASH[1]);  
  793.     HASH[2] = safe_add(c, HASH[2]);  
  794.     HASH[3] = safe_add(d, HASH[3]);  
  795.     HASH[4] = safe_add(e, HASH[4]);  
  796.     HASH[5] = safe_add(f, HASH[5]);  
  797.     HASH[6] = safe_add(g, HASH[6]);  
  798.     HASH[7] = safe_add(h, HASH[7]);  
  799.     }  
  800.     return HASH;  
  801.     }  
  802.     function str2binb (str)
  803.         { 
  804.     var bin = Array();  
  805.     var mask = (1 << chrsz) - 1;  
  806.     for(var i = 0; i < str.length * chrsz; i += chrsz)
  807.         {
  808.         bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);  
  809.     }  
  810.     return bin;  
  811.     }  
  812.  
  813.     function Utf8Encode(string)
  814.         {
  815.         string = string.replace(/\r\n/g,"\n");  
  816.         var utftext = "";  
  817.         for (var n = 0; n < string.length; n++)
  818.             {
  819.             var c = string.charCodeAt(n);  
  820.             if (c < 128)
  821.                 {
  822.                 utftext += String.fromCharCode(c);  
  823.                 }  
  824.             else if((c > 127) && (c < 2048))
  825.                 {
  826.                 utftext += String.fromCharCode((c >> 6) | 192);  
  827.                 utftext += String.fromCharCode((c & 63) | 128);  
  828.                 }  
  829.                 else
  830.                 {
  831.                 utftext += String.fromCharCode((c >> 12) | 224);  
  832.                 utftext += String.fromCharCode(((c >> 6) & 63) | 128);  
  833.                 utftext += String.fromCharCode((c & 63) | 128);  
  834.                 }  
  835.             }  
  836.         return utftext;  
  837.     } 
  838.     
  839.     function binb2hex (binarray)        {
  840.     var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";  
  841.     var str = "";  
  842.     for(var i = 0; i < binarray.length * 4; i++)
  843.         {
  844.         str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +  
  845.         hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);  
  846.         }  
  847.     return str;  
  848.     }
  849.     s = Utf8Encode(s);  
  850.     return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
  851.     },
  852. BrowseSGen:function()
  853.     {    
  854.     gBrowser.selectedTab = gBrowser.addTab('http://www.binaryturf.com'); 
  855.     },    
  856. wOpen:function(url)
  857.         {
  858.         var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  859.         var wmi = wm.QueryInterface(Components.interfaces.nsIWindowMediator);
  860.         var win = wmi.getMostRecentWindow("navigator:browser");
  861.         if (win)
  862.             {
  863.             var tab = win.gBrowser.addTab(url);
  864.             win.gBrowser.selectedTab = tab;
  865.             return;
  866.             }
  867.         },        
  868. clrtabsUnload: function()
  869.         {
  870.         clrPrefObserver.unregister();
  871.         }
  872.     }
  873.  
  874. var clrPrefObserver =
  875.     {
  876.     register: function()
  877.         {
  878.         var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  879.         this._branch = prefService.getBranch("extensions.clrtabs.");
  880.         this._branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
  881.         this._branch.addObserver("", this, false);
  882.         },
  883.     unregister: function()
  884.         {
  885.         if(!this._branch) return;
  886.         this._branch.removeObserver("", this);
  887.         },
  888.     
  889.     observe: function(aSubject, aTopic, aData)
  890.         {
  891.         if(aTopic != "nsPref:changed") return;         
  892.         var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.clrtabs.");
  893.         //
  894.         switch (aData)
  895.             {
  896.             case "fadedeg":                
  897.                 ct.fadedeg = prefBranch.getIntPref("fadedeg");
  898.                 ct.fadeAllTabs();
  899.                 break;
  900.             case "scheme":                
  901.                 ct.scheme = prefBranch.getIntPref("scheme");
  902.                 ct.showRecolor();
  903.                 break;                 
  904.             case "menu":                
  905.                 ct.initTabcontext();
  906.                 ct.showRecolor();
  907.                 break;
  908.             case "enabledomain":
  909.                 ct.enabledomain=prefBranch.getBoolPref("enabledomain");
  910.                 break;
  911.             case "dpref":
  912.                 ct.dpref=prefBranch.getCharPref("dpref");
  913.                 ct.dpref=ct.dpref.split("`");
  914.                 break;
  915.             case "standout":
  916.                 ct.standout=prefBranch.getBoolPref("standout");
  917.                 if(ct.standout)
  918.                     {
  919.                     gBrowser.selectedTab.className = gBrowser.selectedTab.className+" standout";                
  920.                     }
  921.                 else
  922.                     {
  923.                     for(var count=0;count< gBrowser.mTabContainer.childNodes.length;count++)                        
  924.                         {
  925.                         if(gBrowser.mTabContainer.childNodes[count].className.match(" standout"))
  926.                             {
  927.                             gBrowser.mTabContainer.childNodes[count].className=gBrowser.mTabContainer.childNodes[count].className.replace(" standout","")
  928.                             }
  929.                         }
  930.                     }
  931.                 break;
  932.             case "advanced":                
  933.                 ct.adv=prefBranch.getBoolPref("advanced");                
  934.                 if(ct.adv==false)
  935.                     {                
  936.                     ct.satmax=95;
  937.                     ct.satmin=30;
  938.                     ct.lummax=78;
  939.                     ct.lummin=68;
  940.                     ct.sat=60;
  941.                     ct.lum=73;
  942.                     }
  943.                 else
  944.                     {                    
  945.                     ct.satmax=prefBranch.getIntPref("satmax");
  946.                     ct.satmin=prefBranch.getIntPref("satmin");
  947.                     ct.lummax=prefBranch.getIntPref("lummax");
  948.                     ct.lummin=prefBranch.getIntPref("lummin");
  949.                     ct.sat=prefBranch.getIntPref("sat");
  950.                     ct.lum=prefBranch.getIntPref("lum");
  951.                     }
  952.                  
  953.                 break;
  954.             case "satmax":
  955.                 ct.satmax=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.satmax");
  956.                 break;
  957.             case "satmin":
  958.                 ct.satmin=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.satmin");
  959.                 break;
  960.             case "lummax":
  961.                 ct.lummax=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.lummax");
  962.                 break;
  963.             case "lummin":
  964.                 ct.lummin=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.lummin");
  965.                 break;
  966.             case "sat":
  967.                 ct.sat=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.sat");
  968.                 break;
  969.             case "lum":
  970.                 ct.lum=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getIntPref("extensions.clrtabs.lum");
  971.                 break;
  972.             case "bgpicpath":
  973.                 if(ct.isSeamonkey)
  974.                     {
  975.                     ct.setSeamonkeyContainerBg(true);                    
  976.                     }
  977.                 else
  978.                     {
  979.                     gBrowser.mTabContainer.style.backgroundImage="url("+prefBranch.getCharPref("bgpicpath")+")";
  980.                     gBrowser.mTabContainer.style.backgroundRepeat="repeat";
  981.                     }
  982.                 break;
  983.             case "txtreverse":
  984.                 ct.txtreverse = prefBranch.getBoolPref("txtreverse");
  985.                 ct.reverseTxtColor();
  986.                 break;            
  987.             case "bgpic":
  988.                 //ct.cl("bgpic changed");
  989.                 var togglePic = prefBranch.getBoolPref("bgpic");
  990.                 //ct.cl("bgpic is= "+ togglePic);
  991.                 ct.cl("bgpic changed")
  992.                 if(togglePic)
  993.                     {
  994.                     if(ct.isSeamonkey)
  995.                         {
  996.                         ct.cl("this is seamonkey")
  997.                         ct.setSeamonkeyContainerBg(true);
  998.                         }
  999.                     else
  1000.                         {
  1001.                         ct.cl("enabling in firefox")
  1002.                         gBrowser.mTabContainer.style.backgroundImage="url("+prefBranch.getCharPref("bgpicpath")+")";
  1003.                     gBrowser.mTabContainer.style.backgroundRepeat="repeat";
  1004.                         }
  1005.                     }
  1006.                 else
  1007.                     {
  1008.                     if(ct.isSeamonkey)
  1009.                         {
  1010.                         ct.setSeamonkeyContainerBg(false);
  1011.                         }
  1012.                     else
  1013.                         {    //not seamonkey
  1014.                         ct.cl("disabling in firefox")
  1015.                         gBrowser.mTabContainer.style.backgroundImage="none";
  1016.                         gBrowser.mTabContainer.style.backgroundRepeat="no-repeat";                        
  1017.                         }
  1018.                     }
  1019.                 break;
  1020.             }         
  1021.         }
  1022.     }
  1023.  
  1024. var clrUrlListener =
  1025.     {
  1026.     QueryInterface: function(aIID)
  1027.         {
  1028.         if (aIID.equals(Components.interfaces.nsIWebProgressListener) || aIID.equals(Components.interfaces.nsISupportsWeakReference) || aIID.equals(Components.interfaces.nsISupports))
  1029.                  return this;
  1030.         throw Components.results.NS_NOINTERFACE;
  1031.         },
  1032.     onLocationChange: function(aProgress, aRequest, aURI)
  1033.         { 
  1034.         var doc = aProgress.DOMWindow.document;
  1035.         var tab = gBrowser.mTabs[gBrowser.getBrowserIndexForDocument(doc)];         
  1036.         if(ct.clrSession.getTabValue(tab,"ctreadonly") == 1)
  1037.             {
  1038.             return;
  1039.             } 
  1040.         var tabClr;
  1041.         try
  1042.             { 
  1043.             var host = tab.linkedBrowser.contentDocument.location.host;
  1044.             var url = tab.linkedBrowser.contentDocument.location;
  1045.             var testWWW = /^www\.(.+\..+)$/.exec(host); 
  1046.             //tabClr = 'hsl('+Math.abs(ct.clrHash(host))%360+','+60+'%,'+73+'%)'; //use fixed values for sat and lum for host. to do - will use userprefs later for them -  
  1047.             var colored = 0;
  1048.             if(ct.enabledomain)
  1049.                 { 
  1050.                 for (i=0;i<ct.dpref.length;i++)
  1051.                     { 
  1052.                     if(host.match(ct.dpref[i].split("~")[0]))
  1053.                         {
  1054.                         tabClr = ct.dpref[i].split("~")[1];
  1055.                         colored = 1;//set the flag that the domain got a color
  1056.                         }
  1057.                     }
  1058.                 if(colored == 0) //if  the domain didn't get a match, (preference - color unmatched domains)generate a default color?
  1059.                     {
  1060.                     //if(ct.adv == true)
  1061.                     //    {
  1062.                         tabClr = 'hsl('+Math.abs(ct.clrHash(host))%360+','+ct.sat+'%,'+ct.lum+'%)';
  1063.                     //    }
  1064.                     //else
  1065.                     //    {
  1066.                     //    tabClr = 'hsl('+Math.abs(ct.clrHash(host))%360+','+60+'%,'+73+'%)';
  1067.                     //    }
  1068.                     }
  1069.                 }
  1070.             else
  1071.                 {
  1072.                 //if(ct.adv == true)
  1073.                 //    {
  1074.                     tabClr = 'hsl('+Math.abs(ct.clrHash(host))%360+','+ct.sat+'%,'+ct.lum+'%)';
  1075.                 //    }
  1076.                 //else
  1077.                 //    {
  1078.                 //    tabClr = 'hsl('+Math.abs(ct.clrHash(host))%360+','+60+'%,'+73+'%)';
  1079.                 //    }
  1080.                 }
  1081.             ct.setColor(tab,tabClr);            
  1082.             }
  1083.         catch (e)
  1084.             {
  1085.             var host = "about:blank"; // might not always be true, but this makes us ignore it.
  1086.             tabClr ='-moz-dialog'; //use fixed values for sat and lum for host. to do - will use userprefs later for them
  1087.             }
  1088.         },
  1089.     // For definitions of the remaining functions see XulPlanet.com
  1090.     onStateChange:function() { return 0;},
  1091.     onProgressChange: function() { return 0;},
  1092.     onStatusChange: function() { return 0;},
  1093.     onSecurityChange: function() { return 0;},
  1094.     onLinkIconAvailable: function() { return 0;}
  1095.     }